const app = getApp()

import {
  get_para,
  share_by_property,
} from '../../api/request'


Page({
  data: {
    pages: '20', //幻灯片页数 从1到pages
    ppt: [], //幻灯片文件
    isRotating: false, //没有旋转    
    property_code: '',
  },

  onLoad: function (options) {
    this.setData({
      property_code: options.property_code
    })
  },

  //小程序分享信息查询
  share_by_property(property_code) {
    var data = {
      para: [property_code]
    }
    share_by_property(data).then(res => {
      app.globalData.share_title = res.data[0].SHARE_TITLE
      app.globalData.share_img_url = res.data[0].SHARE_IMG_URL
      app.globalData.signature_name=wx.getStorageSync('signature_name'),

      this.user_log_record(app.globalData.cur_my_openid, app.globalData.cur_my_name, '', '', app.globalData.cur_property_code,
        app.globalData.cur_property_name, '1', '1', '1')
    })
  },


  onReady: function () {

    //获取PPT页数
    var data = {
      para: ['PPT_PAGES']
    }
    get_para(data).then(res => {
      this.setData({
        pages: res.data[0].PARA_VALUE
      })
      var ppt = []
      for (var i = 0; i < this.data.pages; i++) {
        var ppt_url = ['https://yz.2alive.cn/image/ppt/幻灯片' + (i + 1) + '.JPG']
        ppt.push({
          PPT_URL: ppt_url
        })
      }

      this.setData({
        ppt,
      })

      //      wx.showModal({
      //        title: '横屏显示效果最好',
      //        content: '请打开手机设置：自动旋转功能',
      //        showCancel: false,
      //      })
    })
  },

  onShow: function () {
    let that = this;
    wx.onWindowResize(function (res) {
      if (res.deviceOrientation === 'landscape') {
        that.isRotating = true;
      } else {
        that.isRotating = false;
      }
    })
  },

  onHide: function () {

  },

  onUnload: function () {

  },

  onPullDownRefresh: function () {

  },

  onReachBottom: function () {

  },


  //分享朋友圈
  onShareTimeline: function () {
    return {
      title: app.globalData.signature_name + '关于《业主我当家》微信小程序介绍PPT及演示',
      query: 'property_code=' + this.data.property_code,
      imageUrl: 'https://yz.2alive.cn/image/logo.png',
    }
  },


  onShareAppMessage: function () {
    return {
      title: app.globalData.signature_name + '关于《业主我当家》微信小程序介绍PPT及演示',
      path: '/pages/ppt/index?property_code=' + this.data.property_code,
      imageUrl: app.globalData.share_img_url,
    }
  },

})